﻿using System;

namespace XchangeStreamer.Utilities
{
    public static class Printer
    {
        public static void PrintLine()
        {
            Console.WriteLine(new string('-', 73));
        }

        public static void PrintRow(params string[] columns)
        {
            if (columns != null && columns.Length > 0)
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                string[] alignCentres = new string[columns.Length];

                //sb.Append("|");
                for (int i = 0; i < columns.Length; i++)
                {
                    sb.Append("{");
                    sb.Append(i);
                    sb.Append("}");

                    alignCentres[i] = AlignCentre(columns[i], (i == 0 ? 40 : 10));
                }
                //sb.Append("|");

                Console.WriteLine(string.Format(sb.ToString(), alignCentres));
            }
        }

        private static string AlignCentre(string text, int width)
        {
            if (string.IsNullOrEmpty(text))
            {
                return new string(' ', width);
            }
            else
            {
                return text.PadRight(width - (width - text.Length) / 2).PadLeft(width);
            }
        }
    }
}
